Skip to content

获取随机浮点数 - GetRandomDouble

函数简介

获取指定范围内的随机浮点数,使用线程独立的随机种子,确保多线程环境下的随机性。

接口名称

GetRandomDouble

DLL调用

c
double GetRandomDouble(long instance, double min, double max);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
min双精度浮点数随机数的最小值(包含)。
max双精度浮点数随机数的最大值(包含)。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
double v = ola.GetRandomDouble(0.0, 1.0);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
double v = ola.GetRandomDouble(0.0, 1.0);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
v = ola.GetRandomDouble(0.0, 1.0)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
double v = ola.GetRandomDouble(0.0, 1.0);
cpp
var ola = com("OlaPlug.OlaSoft")
var v = ola.GetRandomDouble(0.0, 1.0)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
v = ola.GetRandomDouble(0.0, 1.0)
text
.局部变量 ola, OLAPlug
ola.创建 ()
v = ola.GetRandomDouble (0.0, 1.0)
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var v = ola.GetRandomDouble(0.0, 1.0);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
小数 v = ola.GetRandomDouble(0.0, 1.0)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
double v = ola.GetRandomDouble(0.0, 1.0);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
double v = GetRandomDouble(0.0, 1.0);
csharp
using System.Runtime.InteropServices;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();

long instance = CreateCOLAPlugInterFace();
double v = GetRandomDouble(0.0, 1.0);
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
v = ola.GetRandomDouble(0.0, 1.0)

返回值

返回值说明
(返回值)返回指定范围内的随机浮点数(双精度浮点数)。

注意事项

项目说明
随机数包含最小值和最大值返回的随机数包含最小值和最大值。
每个线程使用独立的随机种子每个线程使用独立的随机种子,确保多线程环境下的随机性。